'use strict';

function checksumFile(algorithm, path) {
    return new Promise(function (resolve, reject) {
        let fs = require('fs');
        let crypto = require('crypto');

        let hash = crypto.createHash(algorithm).setEncoding('hex');
        fs.createReadStream(path)
            .once('error', reject)
            .pipe(hash)
            .once('finish', function () {
                resolve(hash.read());
            });
    });
}
// checksumFile('sha1', process.argv[2]).then(function (hash) {
//     console.log('hash:', hash);
// });

module.exports={
    checksumFile
};